<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Admin\Menu;

class MenuController extends Controller
{
    public function getList(Request $request)
    {
        $pageSize = $request['pageSize'];

        $menuModel = new Menu;
        $data = $menuModel->getList($pageSize);

        return $data;
    }

    public function handle(Request $request)
    {
        $data = [];
        $data['id'] = $request['id'];
        $data['pid'] = empty($request['pid']) ? 0 : $request['pid'];
        $data['title'] = $request['title'];
        $data['url'] = empty($request['url']) ? '' : $request['url'];
        $data['icon'] = empty($request['icon']) ? '' : $request['icon'];
        $data['level'] = $request['level'];
        $data['sort'] = $request['sort'];

        $menuModel = new Menu;
        $result = $menuModel->handle($data);

        return $result;
    }

    public function getFirstMenu()
    {
        $menuModel = new Menu;
        $data = $menuModel->getFirstMenu();

        return $data;
    }

    public function getSecondMenu(Request $request)
    {
        $pid = $request['pid'];

        $menuModel = new Menu;
        $data = $menuModel->getSecondMenu($pid);

        return $data;
    }

    public function delete(Request $request)
    {
        $id = $request['id'];
        $menuModel = new Menu;
        $result = $menuModel->deleteAction($id);

        return $result;
    }
}
